package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherDao {
    static Teacher[] teachers = new Teacher[5];


    public boolean addTeacher(Teacher t) {
        int index = -1;
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if(teacher == null){
                index = i;
                break;
            }
        }
        if(index==-1){
            return false;
        }else{
            teachers[index]=t;
            return true;
        }
    }

    public Teacher[] findAllTeacher() {
        return teachers;
    }

    public void deleteTeacher(String delId) {
        int index = getIndex(delId);
        teachers[index] = null;

    }

    public int getIndex(String delId) {
        int index = -1;
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if(teacher!=null&&teacher.getId().equals(delId)){
                index = i;
                break;
            }
        }
        return index;
    }

    public void updateTeacher(String updateId, Teacher t) {
        int index = getIndex(updateId);
        teachers[index] = t;
    }
}
